package com.dimples.dd.system.mq.consumer.sms;

import cn.hutool.core.util.StrUtil;
import com.dimples.dd.common.constant.DDConstant;
import com.dimples.dd.system.mq.message.sms.SmsSendMessage;
import com.dimples.dd.system.service.SmsSendService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 针对 {@link SmsSendMessage} 的消费者
 *
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2024/11/1
 */
@Component
@Slf4j
public class SmsSendConsumer {

    @Resource
    private SmsSendService smsSendService;

    @EventListener
    @Async // Spring Event 默认在 Producer 发送的线程，通过 @Async 实现异步
    public void onMessage(SmsSendMessage message) {
        log.info(DDConstant.CONFIG_LOG, StrUtil.format("[onMessage][消息内容({})]", message));
        smsSendService.doSendSms(message);
    }

}
